package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.PrdAdaptedSoltDao;
import com.fdb.efp.nls.service.domain.PrdAdaptedSolt;
import com.fdb.efp.nls.service.facade.PrdAdaptedSoltService;
import com.fdb.efp.nls.service.vo.PrdAdaptedSoltVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 产品适配插槽
 * 
 * @author huangwb
 * @since 2018年12月26日 下午4:48:56
 * @version 1.0
 */
@Service("prdAdaptedSoltService")
public class PrdAdaptedSoltServiceImpl implements PrdAdaptedSoltService, FrameworkService {
	private static Logger logger = LoggerFactory.getLogger(PrdAdaptedSoltServiceImpl.class);

	@Autowired
	private PrdAdaptedSoltDao prdAdaptedSoltDao;

	/**
	 * 新增操作
	 */
	@Override
	public int insertPrdAdaptedSolt(PrdAdaptedSoltVO inPrdAdaptedSoltVo) {
		logger.debug("当前新增数据为:" + inPrdAdaptedSoltVo.toString());
		int num = 0;
		try {
			PrdAdaptedSolt prdAdaptedSolt = new PrdAdaptedSolt();
			beanCopy(inPrdAdaptedSoltVo, prdAdaptedSolt);
			num = prdAdaptedSoltDao.insertPrdAdaptedSolt(prdAdaptedSolt);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	@Override
	public int deleteByPk(PrdAdaptedSoltVO inPrdAdaptedSoltVo) {
		logger.debug("当前删除数据条件为:" + inPrdAdaptedSoltVo);
		int num = 0;
		try {
			PrdAdaptedSolt prdAdaptedSolt = new PrdAdaptedSolt();
			beanCopy(inPrdAdaptedSoltVo, prdAdaptedSolt);
			num = prdAdaptedSoltDao.deleteByPk(prdAdaptedSolt);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inPrdAdaptedSoltVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	@Override
	public int updateByPk(PrdAdaptedSoltVO inPrdAdaptedSoltVo) {
		logger.debug("当前修改数据为:" + inPrdAdaptedSoltVo.toString());
		int num = 0;
		try {
			PrdAdaptedSolt prdAdaptedSolt = new PrdAdaptedSolt();
			beanCopy(inPrdAdaptedSoltVo, prdAdaptedSolt);
			num = prdAdaptedSoltDao.updateByPk(prdAdaptedSolt);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inPrdAdaptedSoltVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	@Override
	public PrdAdaptedSoltVO queryByPk(PrdAdaptedSoltVO inPrdAdaptedSoltVo) {

		logger.debug("当前查询参数信息为:" + inPrdAdaptedSoltVo);
		try {
			PrdAdaptedSolt queryPrdAdaptedSolt = new PrdAdaptedSolt();
			beanCopy(inPrdAdaptedSoltVo, queryPrdAdaptedSolt);
			PrdAdaptedSolt queryRslPrdAdaptedSolt = prdAdaptedSoltDao.queryByPk(queryPrdAdaptedSolt);
			if (Objects.nonNull(queryRslPrdAdaptedSolt)) {
				PrdAdaptedSoltVO outPrdAdaptedSoltVo = beanCopy(queryRslPrdAdaptedSolt, new PrdAdaptedSoltVO());
				logger.debug("当前查询结果为:" + outPrdAdaptedSoltVo.toString());
				return outPrdAdaptedSoltVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<PrdAdaptedSoltVO> queryAllOwner(PrdAdaptedSoltVO prdAdaptedSoltVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PrdAdaptedSoltVO> list = null;
		try {
			List<PrdAdaptedSolt> prdAdaptedSolts = prdAdaptedSoltDao.queryAllOwnerByPage(prdAdaptedSoltVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + prdAdaptedSolts.size());
			pageSet(prdAdaptedSolts, prdAdaptedSoltVo);
			list = (List<PrdAdaptedSoltVO>) beansCopy(prdAdaptedSolts, PrdAdaptedSoltVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<PrdAdaptedSoltVO> queryAllCurrOrg(PrdAdaptedSoltVO prdAdaptedSoltVo) {
		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PrdAdaptedSolt> prdAdaptedSolts = prdAdaptedSoltDao.queryAllCurrOrgByPage(prdAdaptedSoltVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + prdAdaptedSolts.size());
		List<PrdAdaptedSoltVO> list = null;
		try {
			pageSet(prdAdaptedSolts, prdAdaptedSoltVo);
			list = (List<PrdAdaptedSoltVO>) beansCopy(prdAdaptedSolts, PrdAdaptedSoltVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<PrdAdaptedSoltVO> queryAllCurrDownOrg(PrdAdaptedSoltVO prdAdaptedSoltVo) {
		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PrdAdaptedSolt> prdAdaptedSolts = prdAdaptedSoltDao.queryAllCurrDownOrgByPage(prdAdaptedSoltVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + prdAdaptedSolts.size());
		List<PrdAdaptedSoltVO> list = null;
		try {
			pageSet(prdAdaptedSolts, prdAdaptedSoltVo);
			list = (List<PrdAdaptedSoltVO>) beansCopy(prdAdaptedSolts, PrdAdaptedSoltVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 根据产品ID和插槽状态查询产品插槽信息
	 * 
	 * @param prdAdaptedSoltVo
	 * @return
	 * @author huangwb
	 * @since 2018年12月28日 上午10:28:03
	 * @version 1.0
	 */
	@Override
	public List<PrdAdaptedSoltVO> queryByPrdIdAndState(PrdAdaptedSoltVO inPrdAdaptedSoltVo) {
		logger.debug("当前查询参数信息为:" + inPrdAdaptedSoltVo);
		List<PrdAdaptedSoltVO> list = null;
		try {
			List<PrdAdaptedSolt> prdAdaptedSolts = prdAdaptedSoltDao.queryByPrdIdAndState(inPrdAdaptedSoltVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + prdAdaptedSolts.size());
			pageSet(prdAdaptedSolts, inPrdAdaptedSoltVo);
			list = (List<PrdAdaptedSoltVO>) beansCopy(prdAdaptedSolts, PrdAdaptedSoltVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

}
